package com.boang.tree;

import java.util.Comparator;
import java.util.TreeSet;

/*
  @author: 13813
  @date: 2024/11/29 13:51
*/
public class TreeSetDemo {
    public static void main(String[] args) {
//        m1();
//        m2();
        /*
            1.创建类 abc 实现 Comparator,
            2.abc a = new abc();
            3.TreeSet<Programmer> tree = new TreeSet<>(a);
         */
        TreeSet<Programmer> tree = new TreeSet<>(
                new Comparator<Programmer>() {
                    @Override
                    public int compare(Programmer o1, Programmer o2) {
                        return o1.name.compareTo(o2.name);
                    }
                }
        );
        tree.add(new Programmer("zhangsan", 20));
        tree.add(new Programmer("lisi", 30));
        tree.add(new Programmer("lisi", 30));

        System.out.println(tree);
    }

    private static void m2() {
        TreeSet<String> tree = new TreeSet<>();
        tree.add("zhangsan");
        tree.add("lisi");
        tree.add("lisi");

        System.out.println(tree);
    }

    private static void m1() {
        TreeSet<Student> tree = new TreeSet<>();
        tree.add(new Student("zhangsan", 20));
        tree.add(new Student("lisi", 30));
        tree.add(new Student("lisi", 30));

        System.out.println(tree);
    }
}
